﻿using System;
using System.Data;
using System.Collections.Generic;
using Wozuji.Common;
using Wozuji.Model;
namespace Wozuji.BLL
{
    /// <summary>
    /// 业务逻辑类targs 的摘要说明。
    /// </summary>
    public class targs
    {
        private readonly Wozuji.DAL.targs dal = new Wozuji.DAL.targs();
        public targs()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int targs_id)
        {
            return dal.Exists(targs_id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Wozuji.Model.targs model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Wozuji.Model.targs model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int targs_id)
        {

            dal.Delete(targs_id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Wozuji.Model.targs GetModel(int targs_id)
        {

            return dal.GetModel(targs_id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public Wozuji.Model.targs GetModelByCache(int targs_id)
        {

            string CacheKey = "targsModel-" + targs_id;
            object objModel = Wozuji.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(targs_id);
                    if (objModel != null)
                    {
                        int ModelCache = Wozuji.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Wozuji.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Wozuji.Model.targs)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetTop10List()
        {
            return dal.GetTop10List();
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Wozuji.Model.targs> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Wozuji.Model.targs> DataTableToList(DataTable dt)
        {
            List<Wozuji.Model.targs> modelList = new List<Wozuji.Model.targs>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Wozuji.Model.targs model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Wozuji.Model.targs();
                    if (dt.Rows[n]["targs_id"].ToString() != "")
                    {
                        model.targs_id = int.Parse(dt.Rows[n]["targs_id"].ToString());
                    }
                    model.targs_Name = dt.Rows[n]["targs_Name"].ToString();
                    if (dt.Rows[n]["targs_desc"].ToString() != "")
                    {
                        model.targs_desc = int.Parse(dt.Rows[n]["targs_desc"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

